package br.com.dev.tcc.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.bean.Corretor;

public class ListaCorretoresAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Corretor> itens;

	public ListaCorretoresAdapter(Context ctx, List<Corretor> itens) {

		this.itens = itens;
		inflater = LayoutInflater.from(ctx);
	}

	@Override
	public int getCount() {

		return itens.size();
	}

	@Override
	public Object getItem(int pos) {

		return itens.get(pos);
	}

	@Override
	public long getItemId(int pos) {

		return pos;
	}

	@Override
	public View getView(int pos, View view, ViewGroup parent) {

		final Corretor corretor = itens.get(pos);

		view = inflater.inflate(R.layout.corretores_lista_item, null);

		((TextView) view.findViewById(R.id.tvValueNome)).setText(corretor
				.getName());

		if (corretor.hasEmail())
			((TextView) view.findViewById(R.id.tvValueEmail)).setText(corretor
					.getEmail());
		else
			((TextView) view.findViewById(R.id.tvValueEmail))
					.setText(R.string.sem_email);

		return view;
	}
}
